<?php
header('Access-Control-Allow-Origin:*');

$json = file_get_contents("user.json");

$arr = json_decode($json, true); 

$arr_usr = $arr["data"];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $usr = $_POST['usr'];
  $pwd = $_POST['pwd'];
  $is = false;
  foreach($arr_usr as $value) {
    if ($value['usr'] == $usr) {
      $is = true;
      if ($value['pwd'] == $pwd) {
        echo $usr;
      } else {
        echo 400;
      }
    } 
  }
  if (!$is) {
    echo 401;
  }
} 